package TCP;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.Socket;

/**
 * @author Cheng-02
 * @version V1.0
 * @Package test
 * @date 2024/4/10 上午10:05
 */
public class Day10_Client_Thread_outclass extends Thread {
    private Socket socket;

    public Day10_Client_Thread_outclass(Socket socket) {
        this.socket = socket;
    }

    @Override
    public void run() {
        try {
            InputStream inputStream = socket.getInputStream();
            InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
            BufferedReader reader = new BufferedReader(inputStreamReader);
            while (true) {
                String line = reader.readLine();
                if (line == null) {
                    break;
                }
                System.out.println(socket.getRemoteSocketAddress() + "说的是:" + line);
            }

        } catch (IOException e) {
            System.out.println(socket.getRemoteSocketAddress() + "离开了聊天室");

        }
    }
}
